package com.hongdee.crm.carConfig.dao.impl;

import com.hongdee.base.basedao.impl.BaseDaoImpl;
import com.hongdee.crm.Constant;
import com.hongdee.crm.carConfig.dao.ITCrmCarConfDao;
import com.hongdee.crm.carConfig.entity.TCrmCarConf;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by My on 2017/5/11.
 */
@Component
public class TCrmCarConfDaoImpl extends BaseDaoImpl implements ITCrmCarConfDao {

    /**
     * 根据ID和公司ID 获得分配规则详情
     * @param id
     * @param companyId
     * @return
     * @throws Exception
     */
    @Override
    public TCrmCarConf getCrmCarConfById(String id, String companyId) throws Exception {
        String sql="from TCrmCarConf where id=:id and companyId=:companyId";
        Map<String,Object> params=new HashMap<>();
        params.put("id",id);
        params.put("companyId",companyId);
        return (TCrmCarConf) this.getHibernateDao().findEntityByHqlWithParams(sql,params);
    }

    /**
     * 查询除VIN分配 方式之外的分配
     * @param companyId
     * @return
     * @throws Exception
     */
    @Override
    public List<TCrmCarConf> getCrmCarConfByNotVin(String companyId) throws Exception {
        String sql="from TCrmCarConf where companyId=:companyId ";
        Map<String,Object> params=new HashMap<>();
        params.put("companyId",companyId);
        List list=this.getHibernateDao().findEntityListByHqlWithParams(sql,params);
        return list;
    }

    /**
     * 获得用户的配置信息
     * @param uid
     * @param companyId
     * @return
     * @throws Exception
     */
    @Override
    public TCrmCarConf getCrmCarConfByUid(String uid, String companyId) throws Exception {
        String sql="from TCrmCarConf where uId=:uId and companyId=:companyId";
        Map<String,Object> params=new HashMap<>();
        params.put("uId",uid);
        params.put("companyId",companyId);
        return (TCrmCarConf) this.getHibernateDao().findEntityByHqlWithParams(sql,params);
    }

    /**
     * 根据角色ID 公司ID获得车辆分配信息
     * @param roleId
     * @param companyId
     * @return
     * @throws Exception
     */
    public List<TCrmCarConf> getCrmCarConfByRoleID(String roleId,String companyId)throws Exception{
        String sql="from TCrmCarConf where roleId=:roleId and companyId=:companyId order by confType ASC";
        Map<String,Object> params=new HashMap<>();
        params.put("roleId",roleId);
        params.put("companyId",companyId);
        return this.getHibernateDao().findEntityListByHqlWithParams(sql,params);
    }
}
